#include "IRenderable.h"
#include "DataManager.h"

/// General Constructor
/**	@param repo - pointer to the data repository. Beware that if this pointer is NULL,
				        you have to delete the renderable manually, and will need custom data inside!
	   @param geometry - vertex buffer data handle. Must be in the same repo
	   @param indices - index buffer data handle. Must be in the same repo
	   @param effect - effect holding render states, shaders, etc.
	   @param type - type of the renderable. @default is RENDERABLE_GEOMETRY */
IRenderable::IRenderable( CDataManager* repo, DATAH geometry, DATAH indices, DATAH effect, uint type )
	: m_pDataRepo(repo), m_DataHandle(NO_DATA), m_Geometry(geometry), m_Indices(indices), m_Effect(effect), m_RenderableType(type) {
	if( !repo ) {
		geometry = NO_DATA;
		indices  = NO_DATA;
		effect   = NO_DATA;
		type 		= NO_DATA;
	}
	else {
		m_DataHandle = repo->Add( this, DATAT_RENDERABLE );
	}
}

/// Non-geometrical Constructor
/**	@param repo - pointer to the data repository. Beware that if this pointer is NULL,
				        you have to delete the renderable manually, and will need custom data inside!
	   @param type - type of the renderable. @default is RENDERABLE_GEOMETRY */
IRenderable::IRenderable( CDataManager* repo, uint type )
	: m_pDataRepo(repo), m_DataHandle(NO_DATA), m_Geometry(NO_DATA), m_Indices(NO_DATA), m_Effect(NO_DATA), m_RenderableType(type) {
	if( repo )
		m_DataHandle = repo->Add( this, DATAT_RENDERABLE );
}

/// Custom constructor
/**	@param type - type of custom renderable */
IRenderable::IRenderable( uint type )
	: m_pDataRepo(NULL), m_DataHandle(NO_DATA), m_Geometry(NO_DATA), m_Indices(NO_DATA), m_Effect(NO_DATA), m_RenderableType(type) {

}

/// Destructor
IRenderable::~IRenderable(  ) {
	if( m_pDataRepo )
		m_pDataRepo->Remove( m_DataHandle );
}


